const path = require("path");

var html_webpack_plugin = require("html-webpack-plugin");
const {
    CleanWebpackPlugin
} = require("clean-webpack-plugin");
// const TerserPlugin = require("terser-webpack-plugin");

const mode = 'index'
const plugins = [
    new CleanWebpackPlugin(),
]
if(mode === 'test'){
    plugins.push( new html_webpack_plugin({
        template: "./src/test/index.html",
        filename: "index.html",
        inject: "body",
    }))
}
const entry = {
    [mode]: `./${mode=='index'?'src':'src/test'}/index.js`,
    'connector': `./src/connector.js`,
}
module.exports = {
    mode: "development",
    module: {
        rules: [{
            test: /\.(ts|js)x?$/,
            exclude: /node_modules/,
            loader: "babel-loader",
        }, ],
    },
    entry,
    externals: {
        "ws": "ws",
        "opn":"opn"
    },
    output: {
        filename: "[name].js",
        path: path.resolve(__dirname, "./"+(mode=='index'?'dist':'test')),
        libraryTarget: "umd",
        library:'default',
        globalObject: 'this',
        environment: {
            arrowFunction: false,
        }
    },
    // optimization: {
    //     usedExports: true,
    //     minimize: true,
    //     minimizer: [
    //         new TerserPlugin({
    //             extractComments: false,
    //         }),
    //     ],
    // },
    plugins,
};